import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _toSafeInteger from "lodash/toSafeInteger";
import _isNil from "lodash/isNil";
import _isEmpty from "lodash/isEmpty";
var _excluded = ["_data"];

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _dec21, _dec22, _dec23, _dec24, _dec25, _dec26, _dec27, _dec28, _class, _class2;

/**
 * 通用导入模块
 * 由于 需要被几个页面用到, 所以需要将 model 换成 state
 * @since 2018-9-12
 * @version 0.0.1

 */
import React, { PureComponent } from 'react';
import { Button, Dropdown, Form, Icon, Menu, Modal, Progress, Select, Tooltip } from 'antd';
import { Bind, Debounce } from 'lodash-decorators';
import uuid from 'uuid/v4';
import { Content, Header } from 'components/Page';
import intl from 'utils/intl';
import formatterCollections from 'utils/intl/formatterCollections';
import notification from 'utils/notification';
import { API_HOST, CPAAS_IMP } from 'utils/config';
import { updateTab } from 'utils/menuTab';
import { createPagination, getCurrentOrganizationId, getResponse } from 'utils/utils';
import { DEBOUNCE_TIME } from 'utils/constants';
import { numberRender } from 'utils/renderer';
import { downloadFile, queryMapIdpValue } from 'cpaas-front/lib/services/api';
import { deleteImportHistory, importData as _importData, loadDataSource, loadTemplate, queryImportHistory, queryStatus, removeOne, updateOne, validateData as _validateData } from "../../services/commentImportService";
import UploadExcel from "./UploadExcel";
import FileChunkUpload from "./FileChunkUpload";
import List from "./List";
import "./index.less";
import DataImportHistory from "./DataImportHistory";
var AUTO_REFRESH_DEBOUNCE = 5000;
var CommentImport = (_dec = formatterCollections({
  code: ['cimp.comment', 'cimp.commentImport']
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec7 = Bind(), _dec8 = Bind(), _dec9 = Bind(), _dec10 = Bind(), _dec11 = Bind(), _dec12 = Bind(), _dec13 = Bind(), _dec14 = Bind(), _dec15 = Bind(), _dec16 = Bind(), _dec17 = Bind(), _dec18 = Bind(), _dec19 = Debounce(DEBOUNCE_TIME), _dec20 = Bind(), _dec21 = Bind(), _dec22 = Bind(), _dec23 = Bind(), _dec24 = Bind(), _dec25 = Bind(), _dec26 = Bind(), _dec27 = Bind(), _dec28 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_PureComponent) {
  _inherits(CommentImport, _PureComponent);

  var _super = _createSuper(CommentImport);

  // 自动刷新的 定时器
  function CommentImport(props) {
    var _this;

    _classCallCheck(this, CommentImport);

    _this = _super.call(this, props);
    _this.autoReloadTimer = void 0;
    var _this$props = _this.props,
        _this$props$sync = _this$props.sync,
        sync = _this$props$sync === void 0 ? false : _this$props$sync,
        _this$props$auto = _this$props.auto,
        auto = _this$props$auto === void 0 ? false : _this$props$auto,
        prefixPatch = _this$props.prefixPatch,
        _this$props$args = _this$props.args,
        args = _this$props$args === void 0 ? 'null' : _this$props$args,
        autoRefreshInterval = _this$props.autoRefreshInterval,
        backPath = _this$props.backPath,
        _this$props$tenantId = _this$props.tenantId,
        tenantId = _this$props$tenantId === void 0 ? getCurrentOrganizationId() : _this$props$tenantId,
        code = _this$props.code,
        action = _this$props.action,
        pathKey = _this$props.pathKey;
    _this.autoRefreshInterval = _toSafeInteger(autoRefreshInterval) || AUTO_REFRESH_DEBOUNCE;
    _this.state = {
      dynamicColumns: [],
      // 动态列
      dataSource: [],
      // 数据源
      pagination: false,
      // 后端分页
      batch: null,
      // 批次号
      status: null,
      // 状态
      defaultSheet: '',
      // 默认sheet
      templateTargetList: [],
      // 模板sheet数据
      sync: sync,
      // 是否是同步的接口
      auto: auto,
      // 是否是 同步自动的接口
      backPath: backPath || undefined,
      // 返回地址, 如果返回地址为空, 设置为 undefined
      // 兼容 两个模式, 1: 使用者指定前缀, 2: 前缀由服务端确认
      prefixPatch: prefixPatch,
      // 客户端路径前缀
      fragmentFlag: 0,
      // 是否分片上传
      importStatus: [],
      // 数据导入状态
      // searchDataImportStatus: '', // 数据导入状态查询条件
      // // count: 0, // 导入数据总数
      // // ready: 0, // 已完成导入数据条数
      args: JSON.parse(args),
      // 上传文件时传递的数据
      historyVisible: false,
      //
      tenantId: tenantId,
      // 租户id, 是可配置的
      code: code,
      // 导入编码
      action: action,
      // 标题
      key: pathKey,
      // 通用导入tab页的key
      languageType: []
    };
    return _this;
  }

  _createClass(CommentImport, [{
    key: "init",
    value: function init() {
      var _this2 = this;

      queryMapIdpValue({
        importStatus: 'CIMP.DATA_STATUS',
        dataImportStatus: 'CIMP.IMPORT_STATUS'
      }).then(function (res) {
        var responseRes = getResponse(res);

        if (responseRes) {
          _this2.setState(responseRes);
        }
      });
    }
  }, {
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this$state = this.state,
          code = _this$state.code,
          action = _this$state.action,
          key = _this$state.key;

      if (code) {
        this.getTemplate();
      }

      this.init(); // 更新 tab 的标题

      if (key && action) {
        updateTab({
          key: key,
          title: action
        });
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      if (!_isNil(this.autoReloadTimer)) {
        clearInterval(this.autoReloadTimer);
      }

      this.handleToggleAutoRefresh.cancel();
    }
    /**
     * 获取模板(动态列, 客户端前缀)
     */

  }, {
    key: "getTemplate",
    value: function getTemplate() {
      var _this3 = this;

      var _this$state2 = this.state,
          _this$state2$prefixPa = _this$state2.prefixPatch,
          prefixPatch = _this$state2$prefixPa === void 0 ? '' : _this$state2$prefixPa,
          tenantId = _this$state2.tenantId,
          code = _this$state2.code;
      this.showLoading('loadTemplateLoading');
      loadTemplate({
        code: code,
        prefixPatch: prefixPatch,
        tenantId: tenantId
      }).then(function (res) {
        var parsedRes = getResponse(res);

        if (parsedRes) {
          var _res$prefixPatch = res.prefixPatch,
              newPrefixPatch = _res$prefixPatch === void 0 ? '' : _res$prefixPatch,
              templateType = res.templateType,
              _res$templateTargetLi = res.templateTargetList,
              templateTargetList = _res$templateTargetLi === void 0 ? [] : _res$templateTargetLi,
              fragmentFlag = res.fragmentFlag;

          var _ref = templateTargetList[0] || {},
              _ref$templateLineList = _ref.templateLineList,
              templateLineList = _ref$templateLineList === void 0 ? [] : _ref$templateLineList;

          var defaultSheet = templateTargetList[0] && templateTargetList[0].sheetIndex;

          _this3.setState({
            fragmentFlag: fragmentFlag,
            prefixPatch: newPrefixPatch || prefixPatch || (templateType === 'C' ? '' : CPAAS_IMP),
            templateTargetList: templateTargetList,
            defaultSheet: defaultSheet,
            dynamicColumns: templateLineList.map(function (n) {
              return {
                title: n.columnName,
                dataIndex: n.columnCode,
                width: n.columnName.length * 16 + 32,
                columnType: n.columnType,
                required: n.nullable,
                editable: true,
                // 可编辑控制
                tls: n._tls
              };
            })
          });
        }
      }).finally(function () {
        _this3.hiddenLoading('loadTemplateLoading');
      });
    }
    /**
     * 导入状态查询状态改变
     */

  }, {
    key: "handleDataImportStatusChange",
    value: function handleDataImportStatusChange(value) {
      var _this4 = this;

      this.setState({
        searchDataImportStatus: value
      }, function () {
        _this4.getDataSource();
      });
    }
    /**
     * 切换sheet页
     * @param {string} value - sheet页code
     */

  }, {
    key: "handleChangeSheet",
    value: function handleChangeSheet(value) {
      var _this5 = this;

      var _this$state$templateT = this.state.templateTargetList,
          templateTargetList = _this$state$templateT === void 0 ? [] : _this$state$templateT;
      var selectSheet = templateTargetList.find(function (item) {
        return item.sheetIndex === value;
      }) || {};
      var _selectSheet$template = selectSheet.templateLineList,
          templateLineList = _selectSheet$template === void 0 ? [] : _selectSheet$template; // 获取不同sheet页的模板列

      if (templateLineList) {
        this.setState({
          dynamicColumns: templateLineList.map(function (n) {
            return {
              title: n.columnName,
              dataIndex: n.columnCode,
              width: n.columnName.length * 25,
              columnType: n.columnType,
              required: n.nullable,
              editable: true // 可编辑控制

            };
          })
        });
      } else {
        this.setState({
          dynamicColumns: []
        });
      }

      this.setState({
        defaultSheet: value
      }, function () {
        _this5.getDataSource();
      });
    }
    /**
     * 设置loading
     * 将 [loadingStateStr] 置为 true
     * @param {string} loadingStateStr
     */

  }, {
    key: "showLoading",
    value: function showLoading(loadingStateStr) {
      this.setState(_defineProperty({}, loadingStateStr, true));
    }
    /**
     * 取消loading
     * 将 [loadingStateStr] 置为 false
     * @param {string} loadingStateStr
     */

  }, {
    key: "hiddenLoading",
    value: function hiddenLoading(loadingStateStr) {
      this.setState(_defineProperty({}, loadingStateStr, false));
    }
    /**
     * 上传excel成功后设置批次号
     * 成功后自动刷新状态 和 数据
     * @param {string} batch - 批次号
     */

  }, {
    key: "uploadSuccess",
    value: function uploadSuccess(batch) {
      var _this6 = this;

      this.setState({
        batch: batch
      }, function () {
        _this6.refresh();
      });
    }
    /**
     * 获取导入的数据
     * @param {object} [pagination={}] 查询参数
     */

  }, {
    key: "getDataSource",
    value: function getDataSource() {
      var _this7 = this;

      var pagination = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var _this$state3 = this.state,
          prefixPatch = _this$state3.prefixPatch,
          batch = _this$state3.batch,
          sync = _this$state3.sync,
          searchDataImportStatus = _this$state3.searchDataImportStatus,
          defaultSheet = _this$state3.defaultSheet,
          tenantId = _this$state3.tenantId,
          code = _this$state3.code;
      this.setState({
        loadDataSourceLoading: true,
        cachePagination: pagination
      });
      loadDataSource({
        sync: sync,
        templateCode: code,
        batch: batch,
        prefixPatch: prefixPatch,
        tenantId: tenantId
      }, _objectSpread({
        sheetIndex: defaultSheet,
        status: searchDataImportStatus
      }, pagination)).then(function (res) {
        var dataSource = getResponse(res);

        if (dataSource) {
          var _dataSource$content = dataSource.content,
              content = _dataSource$content === void 0 ? [] : _dataSource$content;
          var formatData = content.map(function (item) {
            var _item$_data = item._data,
                _data = _item$_data === void 0 ? '{}' : _item$_data,
                reset = _objectWithoutProperties(item, _excluded);

            var newData = JSON.parse(_data);
            return _objectSpread(_objectSpread({}, newData), reset);
          });

          _this7.setState({
            dataSource: formatData,
            pagination: createPagination(dataSource)
          });
        }
      }).finally(function () {
        _this7.hiddenLoading('loadDataSourceLoading');
      });
    }
    /**
     * 获取当前状态
     * @param {object} params
     * @param {object} options - 配置
     * @param {boolean} [options.showMessage=true] - 是否显示信息
     */

  }, {
    key: "fetchStatus",
    value: function fetchStatus() {
      var _this8 = this;

      var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
        showMessage: true
      };
      var _this$state4 = this.state,
          prefixPatch = _this$state4.prefixPatch,
          sync = _this$state4.sync,
          tenantId = _this$state4.tenantId;
      queryStatus({
        sync: sync,
        prefixPatch: prefixPatch,
        tenantId: tenantId
      }, params).then(function (res) {
        _this8.showLoading('queryStatusLoading');

        var statusRes = getResponse(res);

        if (statusRes) {
          _this8.setState({
            status: statusRes.status,
            count: statusRes.count,
            ready: statusRes.ready
          });

          if (options.showMessage) {
            notification.success({
              message: intl.get('cimp.comment.view.message.title.refreshSuccess').d('刷新成功'),
              description: intl.get('cimp.comment.view.message.title.currentStatus', {
                name: res.statusMeaning
              }).d("\u5F53\u524D\u6570\u636E\u72B6\u6001\uFF1A".concat(res.statusMeaning))
            });
          }
        } // 当状态是数据导入完成时，获取导入数据


        if (statusRes.status) {
          var cachePagination = _this8.state.cachePagination;

          _this8.getDataSource(cachePagination);
        }
      }).finally(function () {
        _this8.hiddenLoading('queryStatusLoading');
      });
    }
    /**
     * 模板下载 菜单点击
     */

  }, {
    key: "handleDownloadTemplateClick",
    value: function handleDownloadTemplateClick(e) {
      if (e.key === 'excel') {
        this.handleDownloadTemplateExcel();
      } else if (e.key === 'csv') {
        this.handleDownloadTemplateCSV();
      }
    }
    /**
     * 下载 excel 模板
     */

  }, {
    key: "handleDownloadTemplateExcel",
    value: function handleDownloadTemplateExcel() {
      var organizationId = getCurrentOrganizationId();
      var _this$state5 = this.state,
          prefixPatch = _this$state5.prefixPatch,
          code = _this$state5.code;
      var api = "".concat(API_HOST).concat(prefixPatch, "/v1/").concat(organizationId, "/import/template/").concat(code, "/excel");
      downloadFile({
        requestUrl: api,
        queryParams: [{
          name: 'type',
          value: 'bpmn20'
        }]
      });
    }
    /**
     * 下载 CSV 模板
     */

  }, {
    key: "handleDownloadTemplateCSV",
    value: function handleDownloadTemplateCSV() {
      var organizationId = getCurrentOrganizationId();
      var _this$state6 = this.state,
          prefixPatch = _this$state6.prefixPatch,
          code = _this$state6.code;
      var api = "".concat(API_HOST).concat(prefixPatch, "/v1/").concat(organizationId, "/import/template/").concat(code, "/csv");
      downloadFile({
        requestUrl: api,
        queryParams: [{
          name: 'type',
          value: 'bpmn20'
        }]
      });
    }
    /**
     * 校验数据
     */

  }, {
    key: "validateData",
    value: function validateData() {
      var _this9 = this;

      var _this$state7 = this.state,
          prefixPatch = _this$state7.prefixPatch,
          batch = _this$state7.batch,
          sync = _this$state7.sync,
          tenantId = _this$state7.tenantId,
          code = _this$state7.code;

      if (batch) {
        if (!_isEmpty(prefixPatch)) {
          this.showLoading('validateDataLoading');

          _validateData({
            sync: sync,
            templateCode: code,
            batch: batch,
            prefixPatch: prefixPatch,
            tenantId: tenantId
          }).then(function (res) {
            var validateRes = getResponse(res);

            if (validateRes) {
              _this9.refresh();
            }
          }).finally(function () {
            _this9.hiddenLoading('validateDataLoading');
          });
        } else {
          notification.error({
            description: intl.get("cimp.comment.view.message.error.notConfigured").d('模板客户端路径前缀未配置')
          });
        }
      } else {
        notification.error({
          description: intl.get("cimp.comment.view.message.error.ImportFile").d('请上传导入文件')
        });
      }
    }
    /**
     * 导入数据
     */

  }, {
    key: "importData",
    value: function importData() {
      var _this10 = this;

      var _this$state8 = this.state,
          prefixPatch = _this$state8.prefixPatch,
          batch = _this$state8.batch,
          sync = _this$state8.sync,
          tenantId = _this$state8.tenantId,
          code = _this$state8.code;

      if (batch) {
        if (!_isEmpty(prefixPatch)) {
          this.showLoading('importDataLoading');

          _importData({
            templateCode: code,
            sync: sync,
            batch: batch,
            prefixPatch: prefixPatch,
            tenantId: tenantId
          }).then(function (res) {
            var importDataRes = getResponse(res);

            if (importDataRes) {
              _this10.refresh();
            }
          }).finally(function () {
            _this10.hiddenLoading('importDataLoading');
          });
        } else {
          notification.error({
            message: intl.get("cimp.comment.view.message.error.notConfigured").d('模板客户端路径前缀未配置')
          });
        }
      } else {
        notification.error({
          message: intl.get("cimp.comment.view.message.error.ImportFile").d('请上传导入文件')
        });
      }
    }
    /**
     * 保存单条编辑数据
     * @param {object} form - 表单
     * @param {number} _id - 导入数据记录的id
     * @param {Function} cb - 关闭编辑模式
     */

  }, {
    key: "save",
    value: function save(form, _id, _) {
      var _this11 = this;

      var cb = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function (e) {
        return e;
      };
      var _this$state9 = this.state,
          prefixPatch = _this$state9.prefixPatch,
          sync = _this$state9.sync,
          tenantId = _this$state9.tenantId;
      this.showLoading('updateOneLoading');
      form.validateFields(function (error, row) {
        if (!_isEmpty(error)) {
          _this11.hiddenLoading('updateOneLoading');

          return;
        }

        updateOne({
          sync: sync,
          _id: _id,
          prefixPatch: prefixPatch,
          data: _objectSpread({}, row),
          tenantId: tenantId
        }).then(function (res) {
          var updateOneRes = getResponse(res);

          if (updateOneRes) {
            cb();

            _this11.refresh();
          }
        }).finally(function () {
          _this11.hiddenLoading('updateOneLoading');
        });
      });
    }
    /**
     * 删除记录
     * @param {number} _id - 导入数据记录的id
     * @param {Function} cb - 关闭编辑模式
     */

  }, {
    key: "handleRecordRemove",
    value: function handleRecordRemove(_id) {
      var _this12 = this;

      var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (e) {
        return e;
      };
      var _this$state10 = this.state,
          prefixPatch = _this$state10.prefixPatch,
          tenantId = _this$state10.tenantId;
      this.showLoading('removeOneLoading');
      removeOne({
        _id: _id,
        prefixPatch: prefixPatch,
        tenantId: tenantId
      }).then(function (res) {
        var removeOneRes = getResponse(res);

        if (removeOneRes) {
          cb();

          _this12.refresh();
        }
      }).finally(function () {
        _this12.hiddenLoading('removeOneLoading');
      });
    }
    /**
     * 刷行状态和数据
     * @param {object} options - fetchStatus 的配置
     */

  }, {
    key: "refresh",
    value: function refresh(options) {
      var batch = this.state.batch;

      if (batch) {
        this.fetchStatus({
          batch: batch
        }, options);
      }
    }
  }, {
    key: "handleRefresh",
    value: function handleRefresh() {
      this.refresh();
    }
    /**
     * 切换 自动刷新
     */

  }, {
    key: "handleToggleAutoRefresh",
    value: function handleToggleAutoRefresh() {
      var _this13 = this;

      if (_isNil(this.autoReloadTimer)) {
        this.autoReloadTimer = setInterval(function () {
          _this13.refresh({
            showMessage: false
          });
        }, this.autoRefreshInterval); // 直接先刷新一遍

        this.refresh({
          showMessage: false
        });
      } else {
        clearInterval(this.autoReloadTimer);
        this.autoReloadTimer = null; // 强制更新状态

        this.forceUpdate();
      }
    } // Table

  }, {
    key: "handleTableChange",
    value: function handleTableChange(page, filter, sort) {
      this.getDataSource({
        page: page,
        sort: sort
      });
    } // SearchForm

    /**
     * 临时数据导出
     * @param e
     */

  }, {
    key: "handleTemporaryDataExportClick",
    value: function handleTemporaryDataExportClick(e) {
      var _this$state11 = this.state,
          prefixPatch = _this$state11.prefixPatch,
          batch = _this$state11.batch,
          defaultSheet = _this$state11.defaultSheet,
          searchDataImportStatus = _this$state11.searchDataImportStatus,
          code = _this$state11.code;
      var organizationId = getCurrentOrganizationId();

      if (['excel', 'csv'].includes(e.key)) {
        var api = "".concat(API_HOST).concat(prefixPatch, "/v1/").concat(organizationId, "/import/manager/export/").concat(e.key);
        downloadFile({
          requestUrl: api,
          queryParams: [{
            name: 'sheetIndex',
            value: defaultSheet
          }, {
            name: 'batch',
            value: batch
          }, {
            name: 'status',
            value: searchDataImportStatus
          }, {
            name: 'templateCode',
            value: code
          }].filter(function (param) {
            return param.value !== undefined && param.value !== null;
          })
        });
      }
    }
  }, {
    key: "handleHistoryBtnClick",
    value: function handleHistoryBtnClick() {
      this.setState({
        historyVisible: true
      });
    }
  }, {
    key: "handleHistoryModalOk",
    value: function handleHistoryModalOk() {
      // TODO: 确认
      this.setState({
        historyVisible: false
      });
    }
  }, {
    key: "handleHistoryModalCancel",
    value: function handleHistoryModalCancel() {
      this.setState({
        historyVisible: false
      });
    }
    /**
     * 查询历史记录
     * @param query
     * @return {Promise<void>}
     */

  }, {
    key: "handleQueryImportHistory",
    value: function () {
      var _handleQueryImportHistory = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(query) {
        var _this$state12, prefixPatch, tenantId, code;

        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _this$state12 = this.state, prefixPatch = _this$state12.prefixPatch, tenantId = _this$state12.tenantId, code = _this$state12.code;
                return _context.abrupt("return", queryImportHistory({
                  templateCode: code,
                  prefixPatch: prefixPatch,
                  tenantId: tenantId
                }, query));

              case 2:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      function handleQueryImportHistory(_x) {
        return _handleQueryImportHistory.apply(this, arguments);
      }

      return handleQueryImportHistory;
    }()
    /**
     * 恢复导入批次
     * @return {Promise<void>}
     */

  }, {
    key: "handleHistoryRecordRestore",
    value: function () {
      var _handleHistoryRecordRestore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(record) {
        var _this14 = this;

        return _regeneratorRuntime.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                // 恢复 还需要清空其他数据
                if (!_isNil(this.autoReloadTimer)) {
                  clearInterval(this.autoReloadTimer);
                  this.autoReloadTimer = null;
                }

                this.setState({
                  batch: record.batch,
                  historyVisible: false
                }, function () {
                  _this14.refresh();
                });

              case 2:
              case "end":
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      function handleHistoryRecordRestore(_x2) {
        return _handleHistoryRecordRestore.apply(this, arguments);
      }

      return handleHistoryRecordRestore;
    }()
    /**
     * 删除批次
     * @return {Promise<void>}
     */

  }, {
    key: "handleHistoryRecordDelete",
    value: function () {
      var _handleHistoryRecordDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(record) {
        var _this$state13, prefixPatch, tenantId;

        return _regeneratorRuntime.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                _this$state13 = this.state, prefixPatch = _this$state13.prefixPatch, tenantId = _this$state13.tenantId;
                return _context3.abrupt("return", deleteImportHistory({
                  prefixPatch: prefixPatch,
                  tenantId: tenantId
                }, [record]));

              case 2:
              case "end":
                return _context3.stop();
            }
          }
        }, _callee3, this);
      }));

      function handleHistoryRecordDelete(_x3) {
        return _handleHistoryRecordDelete.apply(this, arguments);
      }

      return handleHistoryRecordDelete;
    }()
  }, {
    key: "render",
    value: function render() {
      var _this$state14 = this.state,
          defaultSheet = _this$state14.defaultSheet,
          _this$state14$dynamic = _this$state14.dynamicColumns,
          dynamicColumns = _this$state14$dynamic === void 0 ? [] : _this$state14$dynamic,
          _this$state14$templat = _this$state14.templateTargetList,
          templateTargetList = _this$state14$templat === void 0 ? [] : _this$state14$templat,
          _this$state14$dataSou = _this$state14.dataSource,
          dataSource = _this$state14$dataSou === void 0 ? [] : _this$state14$dataSou,
          pagination = _this$state14.pagination,
          prefixPatch = _this$state14.prefixPatch,
          fragmentFlag = _this$state14.fragmentFlag,
          batch = _this$state14.batch,
          status = _this$state14.status,
          loadTemplateLoading = _this$state14.loadTemplateLoading,
          validateDataLoading = _this$state14.validateDataLoading,
          importDataLoading = _this$state14.importDataLoading,
          queryStatusLoading = _this$state14.queryStatusLoading,
          loadDataSourceLoading = _this$state14.loadDataSourceLoading,
          updateOneLoading = _this$state14.updateOneLoading,
          removeOneLoading = _this$state14.removeOneLoading,
          sync = _this$state14.sync,
          auto = _this$state14.auto,
          _this$state14$importS = _this$state14.importStatus,
          importStatus = _this$state14$importS === void 0 ? [] : _this$state14$importS,
          dataImportStatus = _this$state14.dataImportStatus,
          searchDataImportStatus = _this$state14.searchDataImportStatus,
          count = _this$state14.count,
          ready = _this$state14.ready,
          args = _this$state14.args,
          _this$state14$history = _this$state14.historyVisible,
          historyVisible = _this$state14$history === void 0 ? false : _this$state14$history,
          backPath = _this$state14.backPath,
          tenantId = _this$state14.tenantId,
          action = _this$state14.action,
          code = _this$state14.code,
          languageType = _this$state14.languageType;
      var uploadExcelProps = {
        args: args,
        sync: sync,
        auto: auto,
        prefixPatch: prefixPatch,
        templateCode: code,
        success: this.uploadSuccess,
        tenantId: tenantId
      };
      var fileChunkUploadProps = {
        key: uuid(),
        prefixPatch: prefixPatch,
        modalProps: {
          width: '1000px'
        },
        organizationId: tenantId,
        templateCode: code,
        disabled: false,
        title: intl.get('cimp.comment.view.button.chunkUpload').d('分片上传')
      };
      var listProps = {
        dynamicColumns: dynamicColumns,
        dataSource: dataSource,
        pagination: pagination,
        importStatus: importStatus,
        onChange: this.handleTableChange,
        processing: {
          queryColumns: loadTemplateLoading,
          loading: loadTemplateLoading || validateDataLoading || importDataLoading || loadDataSourceLoading || updateOneLoading || removeOneLoading
        },
        save: this.save,
        onRemove: this.handleRecordRemove,
        languageType: languageType
      };
      var uploadLoading = updateOneLoading || removeOneLoading;
      var isAutoRefresh = !_isNil(this.autoReloadTimer);
      var templateDownloadMenu = /*#__PURE__*/React.createElement(Menu, {
        onClick: this.handleDownloadTemplateClick
      }, /*#__PURE__*/React.createElement(Menu.Item, {
        key: "excel"
      }, /*#__PURE__*/React.createElement(Icon, {
        type: "excel"
      }), intl.get('cimp.comment.view.button.templateExcel').d('EXCEL')), /*#__PURE__*/React.createElement(Menu.Item, {
        key: "csv"
      }, /*#__PURE__*/React.createElement(Icon, {
        type: "csv"
      }), intl.get('cimp.comment.view.button.templateCSV').d('CSV')));
      var temporaryDataExportMenu = /*#__PURE__*/React.createElement(Menu, {
        onClick: this.handleTemporaryDataExportClick
      }, /*#__PURE__*/React.createElement(Menu.Item, {
        key: "excel"
      }, /*#__PURE__*/React.createElement(Icon, {
        type: "excel"
      }), intl.get('cimp.comment.view.button.templateExcel').d('EXCEL')), /*#__PURE__*/React.createElement(Menu.Item, {
        key: "csv"
      }, /*#__PURE__*/React.createElement(Icon, {
        type: "csv"
      }), intl.get('cimp.comment.view.button.templateCSV').d('CSV'))); // 档 count 为0 时, 是 csv 文件, 为 0 是没有导出进度的

      var isProcessing = ['UPLOADING', 'CHECKING', 'IMPORTING'].includes(status) && count !== 0;
      var processElement = isProcessing ? /*#__PURE__*/React.createElement("div", {
        style: {
          flexGrow: 1,
          display: 'flex',
          flexShrink: 0,
          fontSize: 12,
          alignItems: 'center',
          width: 150
        }
      }, /*#__PURE__*/React.createElement(Progress, {
        size: "small",
        percent: numberRender(ready * 100 / count, 2),
        status: count !== ready ? 'active' : 'success'
      })) : null;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Header, {
        backPath: backPath,
        title: action && (intl.get(action) || action) || intl.get('cpaas.common.title.commonImport').d('通用导入')
      }, /*#__PURE__*/React.createElement(Dropdown, {
        overlay: templateDownloadMenu
      }, /*#__PURE__*/React.createElement(Button, {
        type: "primary"
      }, intl.get('cimp.comment.view.button.downloadTemplate').d('下载模板'), /*#__PURE__*/React.createElement(Icon, {
        type: "down"
      }))), fragmentFlag === 1 && /*#__PURE__*/React.createElement(FileChunkUpload, fileChunkUploadProps), (auto || !fragmentFlag) && /*#__PURE__*/React.createElement(UploadExcel, uploadExcelProps), !auto && /*#__PURE__*/React.createElement(React.Fragment, {
        key: "noAutoSync"
      }, /*#__PURE__*/React.createElement(Button, {
        key: "validate",
        icon: "check-circle-o",
        onClick: this.validateData,
        disabled: !batch,
        loading: validateDataLoading
      }, intl.get('cimp.comment.view.button.validateData').d('数据验证')), /*#__PURE__*/React.createElement(Button, {
        key: "import",
        icon: "to-top",
        onClick: this.importData,
        disabled: uploadLoading || !batch,
        loading: importDataLoading
      }, intl.get('cimp.comment.view.button.importData').d('数据导入'))), /*#__PURE__*/React.createElement(Button, {
        key: "refresh",
        icon: "sync",
        onClick: this.handleRefresh,
        disabled: uploadLoading || !batch,
        loading: queryStatusLoading || loadDataSourceLoading
      }, intl.get('cpaas.common.button.refresh').d('刷新')), /*#__PURE__*/React.createElement(Button, {
        key: "auto-refresh",
        icon: isAutoRefresh ? 'loading' : 'sync',
        onClick: this.handleToggleAutoRefresh,
        disabled: uploadLoading || !batch,
        loading: queryStatusLoading || loadDataSourceLoading
      }, isAutoRefresh ? intl.get('cpaas.common.button.cancelAutoReload').d('取消自动刷新') : intl.get('cpaas.common.button.autoReload').d('自动刷新')), /*#__PURE__*/React.createElement(Button, {
        icon: "profile",
        onClick: this.handleHistoryBtnClick
      }, intl.get('cimp.commentImport.view.button.history').d('历史记录'))), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(Form, {
        layout: "inline",
        style: {
          marginBottom: 16
        }
      }, /*#__PURE__*/React.createElement(Form.Item, {
        label: intl.get('cimp.commentImport.model.commentImport.sheetIndex').d('Sheet')
      }, /*#__PURE__*/React.createElement(Select, {
        disabled: !batch,
        style: {
          minWidth: 100
        },
        value: defaultSheet,
        onChange: this.handleChangeSheet
      }, templateTargetList.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          value: item.sheetIndex,
          key: item.sheetIndex
        }, item.sheetIndexMeaning);
      }))), /*#__PURE__*/React.createElement(Form.Item, {
        label: intl.get('cimp.commentImport.model.commentImport.status').d('导入状态')
      }, /*#__PURE__*/React.createElement(Select, {
        allowClear: true,
        disabled: !status,
        value: searchDataImportStatus,
        style: {
          minWidth: 150
        },
        onChange: this.handleDataImportStatusChange
      }, importStatus.map(function (item) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: item.value,
          value: item.value
        }, item.meaning);
      }))), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Dropdown, {
        disabled: !batch || !status || status === 'UPLOADING',
        overlay: temporaryDataExportMenu
      }, /*#__PURE__*/React.createElement(Button, null, intl.get('cimp.comment.view.button.export').d('数据导出')))), isProcessing ? /*#__PURE__*/React.createElement(Form.Item, {
        label: /*#__PURE__*/React.createElement("span", null, intl.get('cimp.commentImport.view.title.process').d('进度'), "\xA0", /*#__PURE__*/React.createElement(Tooltip, {
          title: intl.get('cimp.commentImport.view.message.processHelp').d('需要刷新，才能更新进度')
        }, /*#__PURE__*/React.createElement(Icon, {
          type: "question-circle-o"
        }))),
        style: {
          textAlign: 'right'
        }
      }, processElement) : null), /*#__PURE__*/React.createElement(List, listProps), /*#__PURE__*/React.createElement(Modal, {
        destroyOnClose: true,
        width: 1000,
        wrapClassName: "ant-modal-sidebar-right",
        transitionName: "move-right",
        title: intl.get('cimp.commentImport.view.title.history').d('导入历史'),
        visible: historyVisible,
        onCancel: this.handleHistoryModalCancel,
        onOk: this.handleHistoryModalOk
      }, /*#__PURE__*/React.createElement(DataImportHistory, {
        dataImportStatus: dataImportStatus,
        queryImportHistory: this.handleQueryImportHistory,
        onRecordRestore: this.handleHistoryRecordRestore,
        onRecordDelete: this.handleHistoryRecordDelete
      }))));
    }
  }]);

  return CommentImport;
}(PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "getTemplate", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "getTemplate"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleDataImportStatusChange", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleDataImportStatusChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleChangeSheet", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleChangeSheet"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "showLoading", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "showLoading"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "hiddenLoading", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "hiddenLoading"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "uploadSuccess", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "uploadSuccess"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getDataSource", [_dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "getDataSource"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "fetchStatus", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "fetchStatus"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleDownloadTemplateClick", [_dec10], Object.getOwnPropertyDescriptor(_class2.prototype, "handleDownloadTemplateClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleDownloadTemplateExcel", [_dec11], Object.getOwnPropertyDescriptor(_class2.prototype, "handleDownloadTemplateExcel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleDownloadTemplateCSV", [_dec12], Object.getOwnPropertyDescriptor(_class2.prototype, "handleDownloadTemplateCSV"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "validateData", [_dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "validateData"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "importData", [_dec14], Object.getOwnPropertyDescriptor(_class2.prototype, "importData"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "save", [_dec15], Object.getOwnPropertyDescriptor(_class2.prototype, "save"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleRecordRemove", [_dec16], Object.getOwnPropertyDescriptor(_class2.prototype, "handleRecordRemove"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "refresh", [_dec17], Object.getOwnPropertyDescriptor(_class2.prototype, "refresh"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleRefresh", [_dec18], Object.getOwnPropertyDescriptor(_class2.prototype, "handleRefresh"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleToggleAutoRefresh", [_dec19, _dec20], Object.getOwnPropertyDescriptor(_class2.prototype, "handleToggleAutoRefresh"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleTableChange", [_dec21], Object.getOwnPropertyDescriptor(_class2.prototype, "handleTableChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleTemporaryDataExportClick", [_dec22], Object.getOwnPropertyDescriptor(_class2.prototype, "handleTemporaryDataExportClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleHistoryBtnClick", [_dec23], Object.getOwnPropertyDescriptor(_class2.prototype, "handleHistoryBtnClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleHistoryModalOk", [_dec24], Object.getOwnPropertyDescriptor(_class2.prototype, "handleHistoryModalOk"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleHistoryModalCancel", [_dec25], Object.getOwnPropertyDescriptor(_class2.prototype, "handleHistoryModalCancel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleQueryImportHistory", [_dec26], Object.getOwnPropertyDescriptor(_class2.prototype, "handleQueryImportHistory"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleHistoryRecordRestore", [_dec27], Object.getOwnPropertyDescriptor(_class2.prototype, "handleHistoryRecordRestore"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleHistoryRecordDelete", [_dec28], Object.getOwnPropertyDescriptor(_class2.prototype, "handleHistoryRecordDelete"), _class2.prototype)), _class2)) || _class);
export { CommentImport as default };